package io.renren.modules.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.admin.entity.AboutUsEntity;
import io.renren.modules.admin.entity.BrandActivityEntity;
import io.renren.modules.admin.entity.CadesStyleEntity;
import io.renren.modules.admin.service.AboutUsService;
import io.renren.modules.admin.service.BrandActivityService;
import io.renren.modules.admin.service.CadesStyleService;
import io.renren.modules.admin.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("web/notLogin")
@Api("未登录接口")
public class WebNotLoginController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private AboutUsService aboutUsService;

    @Autowired
    private CadesStyleService cadesStyleService;

    @Autowired
    private BrandActivityService brandActivityService;

    @GetMapping("/course/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
    })
    @ApiOperation("未登录 课程列表")
    public R list( @ApiIgnore @RequestParam Map<String, Object> params){

        params.put("type","0");
        params.put("isLogin","1");
        PageUtils page = courseService.queryPage(params);
        return R.ok().put("page", page);
    }

    @ApiOperation("关于我们详情")
    @GetMapping("/aboutUs/{id}")
    public R aboutUsList(@PathVariable("id") Long id){
        AboutUsEntity aboutUsEntity = aboutUsService.getById(id);
        return R.ok().put("entity", aboutUsEntity);
    }

    //学员风采
    @ApiOperation("学员风采列表")
    @GetMapping("/cades/list/{type}")
    public R cadesStyleList(  @PathVariable("type") Integer type){
        QueryWrapper<CadesStyleEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("type",type);
        List<CadesStyleEntity> list = cadesStyleService.list(wrapper);
        return R.ok().put("list", list);
    }

    @ApiOperation("加入我们图片列表")
    @GetMapping("/aboutUs/img/list")
    public R aboutUsList(){
        QueryWrapper<AboutUsEntity> wrapper = new QueryWrapper<>();
        wrapper.select("imgs","company_name","title","address","about_us_id");
        wrapper.orderByAsc("about_us_no");
        List<AboutUsEntity> list = aboutUsService.list(wrapper);
        return new R().put("list",list);
    }

    /**
     * 查询 品牌活动
     */
    @ApiOperation("查询品牌活动")
    @GetMapping("brandActivity/{type}")
    public R getBrandActivity(@PathVariable Integer type){
        QueryWrapper<BrandActivityEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("type",type);
        List<BrandActivityEntity> list = brandActivityService.list(wrapper);
        return new R().put("list",list);
    }
}
